<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Pager
 *
 * @author Андрей
 */
class Pager {
    
    private $items_per_page;
    private $current_page;
    private $total_num_of_items;
    private $pager_id;

    public function getLimitFrom() {
        return $this->items_per_page * $this->current_page;
    }
    public function getLimitTo() {
        return $this->getLimitFrom()+$this->items_per_page;  
    }
    public function __construct($items_per_page, $current_page, $current_pager_id,  $pager_id='0') {
       if(!session_id())
       session_start();
       
       if ($current_pager_id != $pager_id) {
            $this->current_page = @$_SESSION['pager_' . $pager_id.'_'.md5(@$_GET['rewritequery'])];
        } else {
            $_SESSION['pager_' . $pager_id.'_'.md5(@$_GET['rewritequery'])] = $current_page;
            $this->current_page = $current_page;
        }
       
       $this->pager_id = $pager_id;
       $this->items_per_page = (int)$items_per_page;
    }
    public function getNumOfPages() {
        return ceil($this->total_num_of_items/$this->items_per_page);
    } 
    public function setTotalNumOfItems($num) {
        $this->total_num_of_items = $num;
    }
    public function getTotalNumOfItems() {
        return $this->total_num_of_items;
    }
    public function getCurrentPage() {
        return $this->current_page;
    }
    public function getPagerId() {
        return $this->pager_id;
    }



}


?>
